package cn.itcast.bos.system.service.impl;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.domain.security.Menu;
import cn.itcast.bos.domain.security.Permission;
import cn.itcast.bos.domain.security.Role;
import cn.itcast.bos.domain.security.User;
import cn.itcast.bos.system.dao.MenuDao;
import cn.itcast.bos.system.dao.PermissionDao;
import cn.itcast.bos.system.dao.RoleDao;
import cn.itcast.bos.system.service.RoleService;

@Service
@Transactional
public class RoleServiceImpl implements RoleService{
	@Autowired
	private RoleDao roleDao;
	@Autowired
	private MenuDao menuDao;
	@Autowired
	private PermissionDao permissionDao;
	@Override
	public List<Role> getRolesByUserId(int id) {
		// TODO Auto-generated method stub
		return roleDao.getRolesByUserId(id);
	}
	@Override
	public List<Role> show() {
		// TODO Auto-generated method stub
		return roleDao.findAll();
	}
	@Override
	public void add(Role role, Integer[] menuIds, Integer[] permissionIds) {
		// TODO Auto-generated method stub
		List<Menu> menus=menuDao.getMenuByIds(menuIds);
		List<Permission> permissions=permissionDao.getPremissionByIds(permissionIds);
		role.getMenus().addAll(menus);
		role.getPermissions().addAll(permissions);
		roleDao.save(role);
	}
	@Override
	public List<Role> getByIds(Integer[] roleIds) {
		// TODO Auto-generated method stub
		return roleDao.getByIds( roleIds);
	}

}
